package enumdemo;

public enum TestEnum {
    RED("red",1),
    BLACK("black",2),
    GREEN("green",3);
//    RED,
//    BLACK,
//    GREEN;

    public String color;
    public int ordinal;

    TestEnum(String color,int ordinal) {
        this.color = color;
        this.ordinal = ordinal;
    }

    public static void main2(String[] args) {
        //以数组形式返回枚举类型的所有成员
        TestEnum[] testEnum = TestEnum.values();
        for (int i = 0; i < testEnum.length; i++) {
            //获得枚举成员的索引位置
            System.out.println(testEnum[i] + " " + testEnum[i].ordinal());
        }

        //将普通字符串转换为枚举实例
        TestEnum testEnum1 = TestEnum.valueOf("RED");
        System.out.println(testEnum1);

        //比较两个枚举成员在定义时的顺序
        System.out.println(BLACK.compareTo(RED));
    }

    public static void main1(String[] args) {
        TestEnum testEnum = TestEnum.GREEN;
        switch (testEnum) {
            case RED:
                System.out.println("red");
                break;
            case BLACK:
                System.out.println("black");
                break;
            case GREEN:
                System.out.println("green");
                break;
            default:
                break;
        }
    }
}
